<?php
    @header("Content-Type:text/html;charset=utf-8");

    @include_once("conn.php");
    
    if(!isset($_GET["id"])){
        $obj = array();
        $obj["status"] = false;
        $obj["msg"] = "请传入完整参数";
        $json = json_encode($obj);
        exit($json);
    }


    $id = $_GET["id"];
    
    // mysqli_query($conn,mysql)   执行mysql语句
    // 返回值
    // 语句执行成功  => 查询(结果对象)
    // 语句执行失败  => false 

    // 查询
    $sql = "select id,name,class,chinese,math,english from `grade` where id = $id";

    // 执行mysql语句
    $result = mysqli_query($conn,$sql);
    // print_r($result);

    $obj = array();
    if($result){

        $item = mysqli_fetch_assoc($result);
        if($item){  //有数据
            // 预处理
            $item["chinese"] = $item["chinese"]*1;
            $item["math"] = $item["math"]*1;
            $item["english"] = $item["english"]*1;
            
            $obj["status"] = true;
            $obj["msg"] = "OK";
            $obj["data"] = $item;
        }else{
            $obj["status"] = false;
            $obj["msg"] = "查询数据不存在!";
        }
    }else{
        $obj["status"] = false;
        $obj["msg"] = "sql语句有误";
        $obj["sql"] = $sql;
    }

    echo json_encode($obj);

?>